package com.groupsix.service.impl;

import com.groupsix.entity.Student;
import com.groupsix.mapper.StudentMapper;
import com.groupsix.service.StudentService;
import com.groupsix.utils.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 董盛昌
 * @Title: ${file_name}
 * @Package ${package_name}
 * @Description: 学生业务逻辑接口实现类
 * @date 2021/10/17 10:51
 */
@Service
public class StudentServiceImpl implements StudentService {

    // 注入studentDao
    @Autowired
    private StudentMapper studentMapper;


    @Override
    public PageInfo findPageInfo(String sName, Integer sStudentid, Integer sClassid, String sClassname, Integer pageIndex, Integer pageSize) {
        PageInfo pi = new PageInfo();
        pi.setPageIndex(pageIndex);
        pi.setPageSize(pageSize);
        //获取总条数
        Integer totalCount = studentMapper.totalCount(sName,sStudentid,sClassid,sClassname);
        if (totalCount>0){
            pi.setTotalCount(totalCount);
            //每一页显示学生信息数
            //currentPage = (pageIndex-1)*pageSize  当前页码数减1*最大条数=开始行数
            List<Student> studentList =	studentMapper.getStudentList(sName,sStudentid,sClassid,sClassname,
                    (pi.getPageIndex()-1)*pi.getPageSize(),pi.getPageSize());
            pi.setList(studentList);
        }
        return pi;
    }

    @Override
    public List<Student> getAll(){
        List<Student> studentList = studentMapper.getAll();
        return studentList;
    }

    //通过id删除学生信息
    @Override
    public int deleteStudent(Integer s_id) {
        return studentMapper.deleteStudent(s_id);
    }
    //添加学生信息
    @Override
    public  int addStudent(Student student) {
        return studentMapper.addStudent(student);
    }
    //修改学生信息
    @Override
    public int updateStudent(Student student) { return studentMapper.updateStudent(student); }

    @Override
    public Student findStudentById (Integer s_id){
        Student s = studentMapper.findStudentById(s_id);
        return  s;
    }


}
